package response

import (
	"gin.project.template/core/types"
	"github.com/gin-gonic/gin"
	"net/http"
)

func SUCCESS(c *gin.Context, data ...interface{}) {
	if data != nil {
		c.JSON(http.StatusOK, types.ResultVo{Code: types.Success, Data: data[0]})
	} else {
		c.JSON(http.StatusOK, types.ResultVo{Code: types.Success})
	}
}

func ERROR(c *gin.Context, messages ...string) {
	if messages != nil {
		c.JSON(http.StatusOK, types.ResultVo{Code: types.Failure, Msg: messages[0]})
	} else {
		c.JSON(http.StatusOK, types.ResultVo{Code: types.Failure})
	}
}

func NotAuth(c *gin.Context, messages ...string) {
	if messages != nil {
		c.JSON(http.StatusOK, types.ResultVo{Code: types.NotAuthorized, Msg: messages[0]})
	} else {
		c.JSON(http.StatusOK, types.ResultVo{Code: types.NotAuthorized, Msg: "Not Authorized"})
	}
}
